//
//  WBNavigationController.swift
//  weibo
//
//  Created by wenquan wang on 11/18/16.
//  Copyright © 2016 wenquan wang. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        print(viewController)
        if childViewControllers.count > 0
        {
            viewController.hidesBottomBarWhenPushed = true
            
            var title = "Back"
            
            if childViewControllers.count == 1{
                title = childViewControllers.first?.title ?? "Back"
            }
        
            if let vc = viewController as? WBBaseViewController{
            
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack:true)
            
            }
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popToParent(){
        popViewController(animated: true)
    }

}
